var t = require;
var e = module;
var o = exports;
var n =
    (this && this.__extends) ||
    (function() {
        var t = function(e, o) {
            return (t =
                Object.setPrototypeOf ||
                ({ __proto__: [] }
                    instanceof Array &&
                    function(t, e) {
                        t.__proto__ = e;
                    }) ||
                function(t, e) {
                    for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                })(e, o);
        };
        return function(e, o) {
            function n() {
                this.constructor = e;
            }
            t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
        };
    })(),
    r =
    (this && this.__decorate) ||
    function(t, e, o, n) {
        var r,
            a = arguments.length,
            i = a < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n);
        else
            for (var s = t.length - 1; s >= 0; s--)
                (r = t[s]) && (i = (a < 3 ? r(i) : a > 3 ? r(e, o, i) : r(e, o)) || i);
        return a > 3 && i && Object.defineProperty(e, o, i), i;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = t("BootConst"),
    i = t("EventData"),
    s = t("GameData"),
    c = t("Util"),
    l = t("View"),
    u = t("Platforms"),
    p = t("Sounds"),
    f = t("WatchVideo"),
    d = t("ConfS"),
    h = t("equipbuy"),
    y = t("fun"),
    g = t("herounlock"),
    v = t("Load"),
    m = t("mainView"),
    _ = t("skillup"),
    A = t("topBar"),
    b = require("./仓库属性战斗力变化飘字"),
    C = require("./等级互换"),
    w = require("./视频升级提示框"),
    O = cc._decorator,
    P = O.ccclass,
    S =
    (O.property,
        (function(t) {
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                return (e.res = "warehouse"), (e.herodata = new i.default(null)), e;
            }
            return (
                n(e, t),
                (e.prototype.view_帮手图片 = function(t) {
                    var e = d.DatasManager.HeroDatasById[s.default.herohelp];
                    t.url.value = e ? e.iconName : "";
                }),
                (e.prototype.view_herovideounlock = function(t, e) {
                    var o;
                    "ID" in e
                        ?
                        (void 0 == (o = s.default.herovideounlock[this.herodata.value.ID]) && (o = 0),
                            (t.string = "视频次数(" + o + "/" + this.herodata.value.Need + ")")) :
                        (void 0 == (o = e[this.herodata.value.ID]) && (o = 0),
                            (t.string = "视频次数(" + o + "/" + this.herodata.value.Need + ")"));
                }),
                (e.prototype.onEnable = function() {
                    this.showView(A.default).buttonActive(!1),
                        s.default.hero ?
                        (this.herodata.value = d.DatasManager.HeroDatasById[s.default.hero]) :
                        (this.herodata.value = d.DatasManager.HeroDatas[0]),
                        s.default.on("equips", this, this.showEquips),
                        s.default.on("heros", this, this.ondata),
                        s.default.on("skillLvs", this, this.ondata);
                }),
                (e.prototype.onDisable = function() {
                    s.default.off("equips", this, this.showEquips),
                        s.default.off("heros", this, this.ondata),
                        s.default.off("skillLvs", this, this.ondata);
                }),
                (e.prototype.ondata = function() {
                    this.herodata.emit();
                }),
                (e.prototype.view_名字 = function(t, e) {
                    t.string = e.Name;
                }),
                (e.prototype.view_sk = function(t, e) {
                    var o = v.default.skeletonDatas[e.spinePath];
                    (t.skeletonData = o),
                    t.setAnimation(0, "Idle", !0),
                        (t.node.scale = e.ScaleHome),
                        this.showEquips();
                }),
                (e.prototype.view_lv = function(t) {
                    t.string = y.getHeroLv(this.herodata.value.ID) + "";
                }),
                (e.prototype.view_zdl = function(t) {
                    t.string = y.getzdl(this.herodata.value) + "";
                }),
                (e.prototype.view_upmoney = function(t, e) {
                    var o = y.getupmoney(e.ID);
                    t.set(o.leixing, o.xiaohao);
                }),
                (e.prototype.showEquips = function() {
                    var t = this.find("sk").getComponent(sp.Skeleton);
                    y.showEquips(t, this.herodata.value);
                }),
                (e.prototype.onClick = function(t, e) {
                    var o = this;
                    switch (t) {
                        case "等级互换":
                            this.hideView(), (C.default.heroid = this.herodata.value.ID), this.showView(C.default);
                            break;
                        case "设为帮手":
                            var n = this.herodata.value;
                            if (null == n) return;
                            if (!s.default.heros.includes(n.ID)) return void c.toast("你还没有这个怪兽");
                            if (s.default.hero == n.ID) return void c.toast("这个怪兽正在出战");
                            s.default.herohelp != n.ID ? (s.default.herohelp = n.ID) : c.toast("已经是帮手了");
                            break;
                        case "close":
                            this.hideView(), this.showView(m.default);
                            break;
                        case "last":
                            var r = d.DatasManager.HeroDatasById[this.herodata.value.ID - 1];
                            null == r && (r = d.DatasManager.HeroDatas[d.DatasManager.HeroDatas.length - 1]),
                                (this.herodata.value = r);
                            break;
                        case "next":
                            var i = d.DatasManager.HeroDatasById[this.herodata.value.ID + 1];
                            null == i && (i = d.DatasManager.HeroDatas[0]), (this.herodata.value = i);
                            break;
                        case "equip":
                            var l = d.DatasManager.EquipDatasById[e];
                            s.default.equips.includes(e) ||
                                (s.default.heros.includes(this.herodata.value.ID) ?
                                    ((h.default.data = l), this.showView(h.default)) :
                                    c.toast("请先解锁该单位"));
                            break;
                        case "skill":
                            var u = d.DatasManager.SkillDatasById[e];
                            (_.default.data = u), this.showView(_.default);
                            break;
                        case "use":
                            (s.default.hero = this.herodata.value.ID), this.herodata.emit();
                            break;
                        case "up":
                            var p = this.uplv();
                            p && p();
                            break;
                        case "mfup":
                            var y = this.uplv();
                            y &&
                                this.showView(w.default).set(
                                    this,
                                    function() {
                                        f.default.show(a.dd.rewards, function() {
                                            y(!0);
                                        });
                                    },
                                    function() {
                                        var t = s.default.herolvs[1];
                                        null == t && (t = 1),
                                            t++,
                                            (s.default.herolvs[1] = t),
                                            (s.default.herolvs = s.default.herolvs),
                                            o.herodata.emit();
                                    }
                                );
                            break;
                        case "unlock":
                            (g.default.data = this.herodata.value), this.showView(g.default);
                            break;
                        case "hero":
                            this.herodata.value = d.DatasManager.HeroDatasById[e];
                            break;
                        case "videounlock":
                            if (2 != this.herodata.value.Type) return;
                            var v = this.herodata.value.ID,
                                A = this.herodata.value.Need,
                                b = s.default.herovideounlock[v];
                            void 0 == b && (b = 0),
                                b >= A ?
                                s.default.heros.includes(v) ||
                                (s.default.heros.push(v),
                                    (s.default.heros = s.default.heros),
                                    this.herodata.emit()) :
                                f.default.show(a.dd.videounlock, function() {
                                    b++,
                                    (s.default.herovideounlock[v] = b),
                                    (s.default.herovideounlock = s.default.herovideounlock),
                                    b >= A &&
                                        (s.default.heros.includes(v) ||
                                            (s.default.heros.push(v),
                                                (s.default.heros = s.default.heros),
                                                o.herodata.emit()));
                                });
                    }
                }),
                (e.prototype.uplv = function() {
                    var t = this;
                    if (s.default.heros.includes(this.herodata.value.ID)) {
                        var e = y.getHeroLv(this.herodata.value.ID),
                            o = y.getupmoney(this.herodata.value.ID);
                        if (y.getHeroPars(this.herodata.value.ID, e + 1))
                            return function(n) {
                                void 0 === n && (n = !1), b.default.变化前属性(t.herodata.value.ID);
                                var r = function() {
                                    (s.default.herolvs[t.herodata.value.ID] = e + 1),
                                    (s.default.herolvs = s.default.herolvs),
                                    t.herodata.emit();
                                    var n = t.find("sk/升级动画"),
                                        r = cc.instantiate(n);
                                    (r.parent = n.parent),
                                    (r.active = !0),
                                    b.default.变化后属性(t.herodata.value.ID),
                                        p.Sounds.playFX("升级"),
                                        u.default.platformCtrl.dd(a.dd.HeroLVUP, {
                                            CostType: o.leixing,
                                            CostNeed: o.xiaohao,
                                            eventTime: Date.now(),
                                            Coins: s.default.jb,
                                            Diamonds: s.default.zs,
                                            HeroID: t.herodata.value.ID,
                                            HeroLV: y.getHeroLv(t.herodata.value.ID)
                                        });
                                };
                                n
                                    ?
                                    r() :
                                    c.pay(o.leixing, o.xiaohao, "怪物升级", t, function() {
                                        r();
                                    });
                            };
                        c.toast("已满级");
                    } else c.toast("请先解锁该单位");
                }),
                (e = r([P], e))
            );
        })(l.default));
o.default = S;